package com.tjbklx1.thread.chap01.practice05;

/**
 * 测试程序的不安全性
 * @author Administrator
 *
 */
public class Main {

	public static void main(String[] args) {
		System.out.println("Testing ...");
		for (int trial = 0; true; trial++) {

			SecurityGate gate = new SecurityGate();
			CheckerThread[] t = new CheckerThread[5];

			// start
			for (int i = 0; i < t.length; i++) {
				t[i] = new CheckerThread(gate);
				t[i].start();
			}
			// 等待终止
			for (int i = 0; i < t.length; i++) {
				try {
					t[i].join();
				} catch (InterruptedException e) {
				}
			}

			if (gate.getCounter() == 0) {
//				System.out.println(".");
			} else {
				System.out.println("SecurityGate is not safe!");
				System.out.println("getCounter() = " + gate.getCounter());
				System.out.println("trial = " + trial);
			}

		}
	}
}
